const path = require('path')
const fs = require('fs');
const { log } = require('console');

module.exports = {
    fetch: function (req, res, views = '', parmas = {}) {
        req.actionName = req.actionName.substr(req.actionName.indexOf('_') + 1);
        views = views ? views : req.actionName;

        // console.log(path.join(__dirname, '..', '..', 'views', req.moduleName, req.controllerName.toLowerCase(), views + '.ejs'));
        let moduleEjs = fs.existsSync(path.join(__dirname, '..', '..', 'views', req.moduleName, req.controllerName.toLowerCase(), views + '.ejs'))

        if(!moduleEjs){
            throw new Error(`${req.moduleName}/${req.controllerName.toLowerCase()}/${views} is not exist`)
        }

        res.render(`${req.moduleName}/${req.controllerName.toLowerCase()}/${views}`, parmas)
    }
}